#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<errno.h>
#include<unistd.h>

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
#include<event.h>
#include<event2/util.h>

void cmd_msg_cb(int fd, short events, void* arg)
{
	char msg[1024] = {0x00};
	
	int ret = read(fd, msg, sizeof(msg));
	if(ret <= 0)
	{
		perror("read failed");
		exit(-1);
	}
	
	printf("read from stdin and recv data:[%s]\n", msg);
}

int main(int argc, char** argv)
{
	struct event_base* base = event_base_new();

	 //监听终端输入事件
    struct event* ev_cmd = event_new(base, STDIN_FILENO,
                                      EV_READ | EV_PERSIST, cmd_msg_cb,
                                      NULL);
	
	event_add(ev_cmd, NULL);
 
    event_base_dispatch(base);
 
    printf("finished \n");
}
